package com.sykj.cloud.system.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.sykj.cloud.common.log.annotation.Log;
import com.sykj.cloud.common.log.enums.LogUserType;
import com.sykj.cloud.common.security.annotation.PreAuthorize;
import com.sykj.cloud.system.domain.SysApplication;
import com.sykj.cloud.system.service.ISysApplicationService;
import com.sykj.cloud.common.core.web.controller.BaseController;
import com.sykj.cloud.common.core.web.domain.AjaxResult;
import com.sykj.cloud.common.core.utils.poi.ExcelUtil;
import com.sykj.cloud.common.core.web.page.TableDataInfo;

/**
 * 系统应用定义Controller
 *
 * @author mr.will
 * @date 2021-03-15
 */
@RestController
@RequestMapping("/application")
public class SysApplicationController extends BaseController
{
    @Autowired
    private ISysApplicationService sysApplicationService;


    /**
     * 新增系统应用定义
     */
    @PreAuthorize(hasPermi = "system:application:add")
    @Log(title = "系统应用定义", logUserType = LogUserType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysApplication sysApplication)
    {
        return toAjax(sysApplicationService.insertSysApplication(sysApplication));
    }

    /**
     * 修改系统应用定义
     */
    @PreAuthorize(hasPermi = "system:application:edit")
    @Log(title = "系统应用定义", logUserType = LogUserType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysApplication sysApplication)
    {
        return toAjax(sysApplicationService.updateSysApplication(sysApplication));
    }

    /**
     * 删除系统应用定义
     */
    @PreAuthorize(hasPermi = "system:application:remove")
    @Log(title = "系统应用定义", logUserType = LogUserType.DELETE)
	@DeleteMapping("/{guids}")
    public AjaxResult remove(@PathVariable String[] guids)
    {
        return toAjax(sysApplicationService.deleteSysApplicationByIds(guids));
    }


    /**
     * 获取系统应用定义详细信息
     */
    @PreAuthorize(hasPermi = "system:application:query")
    @GetMapping(value = "/{guid}")
    public AjaxResult getInfo(@PathVariable("guid") String guid)
    {
        return AjaxResult.success(sysApplicationService.getSysApplicationById(guid));
    }

    /**
     * 导出系统应用定义列表
     */
    @PreAuthorize(hasPermi = "system:application:export")
    @Log(title = "系统应用定义", logUserType = LogUserType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysApplication sysApplication) throws IOException
    {
        List<SysApplication> list = sysApplicationService.listSysApplications(sysApplication);
        ExcelUtil<SysApplication> util = new ExcelUtil<SysApplication>(SysApplication.class);
        util.exportExcel(response, list, "application");
    }


    /**
     * 查询系统应用定义列表
     */
    @PreAuthorize(hasPermi = "system:application:list")
    @GetMapping("/list")
    public TableDataInfo list(SysApplication sysApplication)
    {
        startPage();
        List<SysApplication> list = sysApplicationService.listSysApplications(sysApplication);
        return getDataTable(list);
    }


    /**
     * 查询系统应用定义列表
     */
    @PreAuthorize(hasPermi = "system:application:list")
    @GetMapping("/list/options")
    public AjaxResult listOptions(SysApplication sysApplication)
    {
        List<SysApplication> list = sysApplicationService.listSysApplications(sysApplication);
        return AjaxResult.success(list);
    }

}
